
// test symblo
macro test()
{
//	symbolname = Ask("What symbol do you want to locate?")
	hPrj=GetCurrentProj()
	ifileCnt=GetProjFileCount(hPrj)
	
	hbufRst=NewBuf("Result.txt")
	bufSch=NewBuf("")
	
//    DEBUG_FUNCTION(QueueCmdWithTimeout);
	pattern="DEBUG_FUNCTION(\\(.+\\))"
//Msg("pattern: @pattern@")

	i=0
	while(i<ifileCnt)
	{
	    szFile=GetProjFileName(hPrj, i)
	    hbufFile=OpenBuf(szFile)
	
		lnSch=0
		fCloseBuf=true
		while(1){
			ClearBuf(bufSch)
	    	selRst=SearchInBufEx(hbufFile, pattern, lnSch, 0, 1, 1, 0, bufSch, 0)
			if(""==selRst){
				break
			}
			szFunTrac=GetBufLine(bufSch, 1)
//Msg("szFunTrac: @szFunTrac@, selRst: @selRst@")

			szTgtLn=selRst.lnFirst
			szTgtCh=selRst.ichFirst
//			szLine="Name=\"@szFunTrac@\";File=\"@szFile@\";ln=\"@szTgtLn@\";ich=\"@szTgtCh@\""
			AppendBufLine(hbufRst, "Name=\"@szFunTrac@\";File=\"@szFile@\";ln=\"@szTgtLn@\";ich=\"@szTgtCh@\"")
			iSrcLn=GetBufLineCount(hbufRst)
			SetSourceLink(hbufRst, iSrcLn-1, szFile, selRst.lnFirst)
			
			szFunTrace=FormFunTrace(szFunTrac, "")
			PutBufLine (hbufFile, selRst.lnFirst, szFunTrace)
			fCloseBuf=false
			
			lnSch=selRst.lnLast+1
	    }
	    
	    if(true==fCloseBuf){
    		CloseBuf(hbufFile)
		}
		
	    i=i+1
	}
	
    CloseBuf(bufSch)
    
    hWnd=NewWnd(hbufRst)
	SetCurrentWnd(hWnd)

}



macro FormFunTrace(szFun, szRet)
{
	symbolFun = GetSymbolLocation(szFun)
	if(symbolFun==nil) {
Msg("Invalid name:@szFun@!")
		return
	}
	if( ("Function"!=symbolFun.Type) && ("Method"!=symbolFun.Type) ){
Msg("Invalid name:@szFun@!  @symbolFun@")
		return
	}

	cntPara=0
	hbufPara=NewBuf("")
	
	//
	// get paras
	hsymlChld = SymbolChildren(symbolFun)
	cntChld = SymListCount(hsymlChld)
	i = 0
	while (i < cntChld)
    {
		synblChld = SymListItem(hsymlChld, i)
		if("Parameter"==synblChld.Type){
			InsAndSortParaBuf(hbufPara, synblChld)
			cntPara=cntPara+1
		}
		i=i+1
    }
	SymListFree(hsymlChld)
	
	
	//
	// for FUN_TRACE_PX_RX(funname, p1, ... r)
	if(""==szRet){
		cntRet=0
	}else{
		cntRet=1
	}
	szFunTrace="FUN_TRACE_P@cntPara@_R@cntRet@(@szFun@"
	
	iFunNameId=strlen(szFun)
	iFunNameId=iFunNameId+1
	i=0
	while(i<cntPara){
		symblPara=GetBufLine(hbufPara, i)
		iSymblParaLen=strlen(symblPara.Symbol)
		szPara=strmid(symblPara.Symbol, iFunNameId, iSymblParaLen)
		szFunTrace=cat(szFunTrace, ",@szPara@")
		i=i+1
	}

	if(""!=szRet){
		szFunTrace=cat(szFunTrace, ",@szRet@);")
	}else{
		szFunTrace=cat(szFunTrace, ");")
	}
	
//Msg(szFunTrace)

	CloseBuf(hbufPara)
	
	return szFunTrace
}


// insert symbol:symblPara to special buf line according to the symblPara's location (line and column)
macro InsAndSortParaBuf(hParaBuf, symblPara)
{
	cntBufLn=GetBufLineCount(hParaBuf)
	
	i=0
	while(i<cntBufLn){
		symblCur=GetBufLine(hParaBuf, i)
		if(symblPara.lnName<symblCur.lnName){
//Msg("InsBufLine @i@")
			InsBufLine(hParaBuf, i, symblPara)
			return
		}
		if(symblPara.lnName==symblCur.lnName){
			if(symblPara.ichName<symblCur.ichName){
//Msg("InsBufLine @i@")
				InsBufLine(hParaBuf, i, symblPara)
				return
			}
		}
		
		i=i+1
	}
	
//Msg("AppendBufLine")
	AppendBufLine(hParaBuf, symblPara)
}